home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 7: Sunsite / Linux Cubed Series 7 - Sunsite Vol 1.iso / system / serial / mdm-2.000 / mdm-2 / setup.c < prev    next >
C/C++ Source or Header  |  1993-11-16  |  7KB  |  264 lines

  1. /*************************************************************************
  2. Config loading and parsing code
  3. --------------------------------------------------------------------------
  4.  
  5.     Copyright (C) 1992  Anthony Rumble
  6.  
  7.     This program is free software; you can redistribute it and/or modify
  8.     it under the terms of the GNU General Public License as published by
  9.     the Free Software Foundation; either version 1, or
  10.     any later version.
  11.  
  12.     This program is distributed in the hope that it will be useful,
  13.     but WITHOUT ANY WARRANTY; without even the implied warranty of
  14.     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  15.     GNU General Public License for more details. <copying>
  16.  
  17.     You should have received a copy of the GNU General Public License
  18.     along with this program; if not, write to the Free Software
  19.     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  20.  
  21. --------------------------------------------------------------------------
  22. RCS Info
  23.  
  24. $Header: /home/smilie/bbs/modem/RCS/setup.c,v 1.9 1993/11/16 11:42:21 smilie Exp $
  25.  
  26. $Log: setup.c,v $
  27.  * Revision 1.9  1993/11/16  11:42:21  smilie
  28.  * added INITSPEED
  29.  *
  30.  *
  31.  * Revision 1.7  1993/10/10  06:24:48  smilie
  32.  * added new config options
  33.  *
  34.  * Revision 1.6  1993/09/05  05:05:39  smilie
  35.  * added SCO isms
  36.  *
  37.  * Revision 1.5  1992/12/06  06:52:20  smilie
  38.  * fixed an int/char
  39.  *
  40.  * Revision 1.4  1992/10/11  08:49:33  smilie
  41.  * added IGNORECARRIER to change CONFIG.carrier flag
  42.  *
  43.  * Revision 1.3  1992/10/09  14:29:49  smilie
  44.  * added the timeout to configuration
  45.  *
  46.  * Revision 1.2  1992/10/09  13:43:36  smilie
  47.  * fixed some warnings
  48.  *
  49.  * Revision 1.1  1992/10/09  13:18:22  smilie
  50.  * Initial revision
  51.  *
  52.  
  53. *************************************************************************/
  54.  
  55. /* Feature test switches */
  56. #define _POSIX_SOURCE 1
  57. #define _SETUP_C
  58.  
  59. /* System Headers */
  60. #include <stdio.h>
  61. #include <string.h>
  62. #include <termio.h>
  63.  
  64. /* Local Headers */
  65. #include "modem.h"
  66.  
  67. /* Macros */
  68.  
  69. /* File scope variables */
  70.  
  71. static char setup_rcsid[] = "$Id: setup.c,v 1.9 1993/11/16 11:42:21 smilie Exp $";
  72. #define RCSID setup_rcsid
  73.  
  74. /* External variables */
  75.  
  76. /* External Functions */
  77.  
  78. /* Structures and unions */
  79.  
  80. /* Functions */
  81.  
  82. /*************************************************************************
  83.                 CHECK_CONFIG
  84. *************************************************************************/
  85. int check_config()
  86. {
  87. int ret = 1;
  88. /**/
  89. if (CONFIG.speed == -1)
  90.     {
  91.     flog("CONFIG: no speed. eg/ 'SPEED 19200'\n");
  92.     ret = 0;
  93.     }
  94. if (CONFIG.quiet)
  95.     {
  96.     if (CONFIG.quiet_start == -1)
  97.         {
  98.         flog("CONFIG: no Quiet Start time. eg/ 'QUIET_TIMEON 22'\n");
  99.         ret = 0;
  100.         }
  101.     if (CONFIG.quiet_stop == -1)
  102.         {
  103.         flog("CONFIG: no Quiet Stop time. eg/ 'QUIET_TIMEOFF 2'\n");
  104.         ret = 0;
  105.         }
  106.     if (CONFIG.quiet_str_on[0] == 0)
  107.         {
  108.         flog("CONFIG: no Quiet Start String. eg/ 'QUIET_STRON ATM0|'\n");
  109.         ret = 0;
  110.         }
  111.     if (CONFIG.quiet_str_off[0] == 0)
  112.         {
  113.         flog("CONFIG: no Quiet Stop String. eg/ 'QUIET_STROFF ATM1|'\n");
  114.         ret = 0;
  115.         }
  116.     }
  117.  
  118. return ret;
  119. }
  120. /************************************************************************
  121.             PARSE_CONFIG_STRING
  122. -------------------------------------------------------------------------
  123. Parses the Config Strings, setting the correct internal
  124. configuration structures
  125. *************************************************************************/
  126. void parse_config_string(const char *tststring)
  127. {
  128. char tmps[100];
  129. /**/
  130. if (strncasecmp(tststring, "SPEED", 5) == 0)
  131.     sscanf(tststring, "%s %u", tmps, &CONFIG.speed);
  132. else
  133. if (strncasecmp(tststring, "LOCKED", 6) == 0)
  134.     CONFIG.locked = 1;
  135. else
  136. if (strncasecmp(tststring, "INIT", 4) == 0)
  137.     sscanf(tststring, "%s %[^_]", tmps, CONFIG.init);
  138. else
  139. if (strncasecmp(tststring, "QUIET_STRON", 11) == 0)
  140.     {
  141.     sscanf(tststring, "%s %[^_]", tmps, CONFIG.quiet_str_on);
  142.     CONFIG.quiet = 1;
  143.     }
  144. else
  145. if (strncasecmp(tststring, "QUIET_STROFF", 12) == 0)
  146.     {
  147.     sscanf(tststring, "%s %[^_]", tmps, CONFIG.quiet_str_off);
  148.     CONFIG.quiet = 1;
  149.     }    
  150. else
  151. if (strncasecmp(tststring, "QUIET_TIMEON", 12) == 0)
  152.     {
  153.     sscanf(tststring, "%s %u", tmps, &CONFIG.quiet_start);
  154.     CONFIG.quiet = 1;
  155.     }
  156. else
  157. if (strncasecmp(tststring, "QUIET_TIMEOFF", 13) == 0)
  158.     {
  159.     sscanf(tststring, "%s %u", tmps, &CONFIG.quiet_stop);
  160.     CONFIG.quiet = 1;
  161.     }
  162. else
  163. if (strncasecmp(tststring, "TIMEOUT", 7) == 0)
  164.     {
  165.     sscanf(tststring, "%s %hu", tmps, &CONFIG.timeout);
  166.     }    
  167. else
  168. if (strncasecmp(tststring, "CONNECT", 7) == 0)
  169.     {
  170.     sscanf(tststring, "%s %hu", tmps, &CONFIG.timeout_connect);
  171.     }
  172. else
  173. if (strncasecmp(tststring, "ERRORCORRECT", 12) == 0)
  174.     {
  175.     CONFIG.error_correcting = 1;
  176.     }
  177. else
  178. if (strncasecmp(tststring, "ISSUE", 12) == 0)
  179.     {
  180.     CONFIG.issue = 1;
  181.     }
  182. else
  183. if (strncasecmp(tststring, "ROWS", 4) == 0)
  184.     {
  185.     sscanf(tststring, "%s %u", tmps, &CONFIG.rows);
  186.     }
  187. else
  188. if (strncasecmp(tststring, "COLS", 4) == 0)
  189.     {
  190.     sscanf(tststring, "%s %u", tmps, &CONFIG.cols);
  191.     }
  192. else
  193. if (strncasecmp(tststring, "INITSPEED", 9) == 0)
  194.     sscanf(tststring, "%s %u", tmps, &CONFIG.initspeed);
  195. }
  196. /************************************************************************
  197.             LOAD_ACONFIG
  198. -------------------------------------------------------------------------
  199. Loads a Config given the file name
  200. *************************************************************************/
  201. int load_aconfig(const char *filenam)
  202. {
  203. FILE *fh;
  204. char tmpstr[100];
  205. /**/
  206.  
  207. if ((fh = fopen(filenam, "rt")) == NULL)
  208.     {
  209.     #ifdef DEBUG
  210.     perror(filenam);
  211.     #endif
  212.     return FALSE;
  213.     }
  214. while(!feof(fh))
  215.     {
  216.     fgetstr(tmpstr, sizeof(tmpstr), fh);
  217.     if ((tmpstr[0] != 0) && (tmpstr[0] != '#'))
  218.         {
  219.         parse_config_string(tmpstr);
  220.         }
  221.     }
  222. fclose(fh);
  223. return TRUE;
  224. }
  225. /*************************************************************************
  226.                 LOAD_CONFIG
  227. *************************************************************************/
  228. int load_config()
  229. {
  230. char tmpf[256];
  231. /**/
  232. CONFIG.locked = 0;
  233. CONFIG.speed = -1;
  234. CONFIG.initspeed = 0;
  235. CONFIG.conspeed = 0;
  236. CONFIG.init[0] = 0;
  237. CONFIG.quiet = 0;
  238. CONFIG.quiet_str_on[0] = 0;
  239. CONFIG.quiet_str_off[0] = 0;
  240. CONFIG.quiet_start = -1;
  241. CONFIG.quiet_stop = -1;
  242. CONFIG.timeout = 10;        /* Set CR timeout to 10 seconds */
  243. CONFIG.timeout_connect = 2;    /* Set CONNECT timeout to 2 seconds */
  244. CONFIG.error_correcting = 0;    /* Default to NON-Error correcting */
  245. CONFIG.issue = 0;        /* Default is to show issue */
  246. CONFIG.rows = 24;        /* Default rows */
  247. CONFIG.cols = 80;        /* Default cols */
  248.  
  249. if (!load_aconfig("/etc/default/modem"))
  250.     {
  251.     flog("load_config: ERROR cannot load /etc/default/modem\n");
  252.     exit(1);
  253.     }
  254. sprintf(tmpf, "/etc/default/%s", stty);
  255. (void)load_aconfig(tmpf);
  256.  
  257. if (check_config())
  258.     return TRUE;
  259.  
  260. return FALSE;
  261. }
  262.  
  263.  
  264.